/**
 * Created by vincent on 2017/9/27.
 */
moduleQuiz.controller('QuizQuery', function (LanguageService, $scope, $rootScope, $state, $log, DialogService, LoadingService, ConstantService, GaugeResource, EnumService, GaugeEstimateGroupResource) {
    initPage($scope);
    $scope.$on("$viewContentLoaded", function () {
        $scope.currentState = $state.current;
        pageOnLoad();
        ConstantService.addState($state.current, true, LanguageService.language('测试题管理'));
    });

    $scope.queryPara = {};
    $scope.queryGaugeList = function (pageNo) {
        //LoadingService.show();
        GaugeResource.queryList({pageNo: pageNo - 1, pageSize: 10}, $scope.queryPara, function (gaugeResult) {
            $log.debug("量表搜索结果", gaugeResult);
            $scope.gaugeResult = gaugeResult;
            $scope.pagination.setPage(gaugeResult, pageNo);
            //LoadingService.hide();
        });
    };
    $scope.pagination = new Pagination();
    $scope.pagination.setPageClickFn($scope.queryGaugeList);
    $scope.queryGaugeList($scope.pagination.currentPageNo);

    $scope.add = function () {
        DialogService.open("addQuiz", $scope);
    };

    $scope.edit = function (gaugeView) {
        $scope.currentGauge = gaugeView;
        //LoadingService.show();
        GaugeResource.findById({gaugeTemplateId: gaugeView.gaugeTemplateId}, function (gaugeResult) {
            $log.debug("量表搜索结果", gaugeResult);
            $scope.editingGauge = gaugeResult;
            //LoadingService.hide();
            DialogService.open("editQuiz", $scope);
        }, function () {
            //LoadingService.hide();
        });
    };

    $scope.checkTopic = function (gaugeView) {
        //ConstantService.setItem("currentGaugeTemplateId",gaugeView.gaugeTemplateId);
        $state.go("sz.quizTopicQuery", {
            quizTemplateId: gaugeView.gaugeTemplateId
        });
    };

    $scope.refreshEstimate = function (gaugeView) {
        var param = {
            gaugeTemplateId: gaugeView.gaugeTemplateId
        }
        GaugeEstimateGroupResource.refreshEstimate({}, param, function () {
            $log.debug("测试评价刷新");
            //LoadingService.hide();
            Alert.success("测试评价刷新成功！");
            //DialogService.open("editGauge",$scope);
        }, function () {
            //LoadingService.hide();
        });
    }
});